package offer.offer01;

/**
 * 注意一下边界条件即可
 */
public class S18删除链表节点 {
    public ListNode deleteNode(ListNode head, int val) {
        if(head == null)
            return null;
        ListNode result = head;//获取链表头, 返回用
        ListNode previous = head;//前一项
        ListNode currPosi = head.next;
        if(head.val == val){
            return head.next;
        }else if(head.next == null) {
            return head;
        }else{
            while(currPosi != null){
                if(currPosi.val == val){
                    previous.next = currPosi.next;
                    break;
                }else{
                    previous = previous.next;
                    currPosi = currPosi.next;
                }
            }
        }
        return result;
    }
}
